package com.maochang.top.service;

import com.maochang.top.bean.Account;
import com.maochang.top.config.SpringConfig;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.VoidType;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * 一、注解整合Junit
 *   1.Spring接管Junit的运行权,使用Spring的专用的Junit类加载器
 *   2.Junit测试用例设定对应的Spring容器
 *   注意:
 *   1.从Spring5.0以后,要求Junit的版本必须是4.12及以上
 *   2.Junit仅用于单元测试,不能将Junit的测试类,配置成Spring的bean,否则该配置将会被打包进入到工程中
 * 二、导入Spring整合Junit坐标
 *   <dependency>
 *             <groupId>org.springframework</groupId>
 *             <artifactId>spring-test</artifactId>
 *             <version>5.3.9</version>
 *         </dependency>
 *         <dependency>
 *             <groupId>junit</groupId>
 *             <artifactId>junit</artifactId>
 *             <version>4.12</version>
 *             <scope>test</scope>
 *   </dependency>
 * 三、Spring整合Junit测试用例注解格式
 *  @RunWith(SpringJUnit4ClassRunner.class)
 *  @ContextConfiguration(classes = SpringConfig.class)
 *  public class JunitTestApp {
 *
 *  }
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class JunitTestApp {

    @Autowired
    private   AccountService accountServiceImpl;

    @Test
    public void  test01(){
        System.out.println("测试用例1");
        Account account = accountServiceImpl.findById(1);
        System.out.println(account);
        //断言机制
        Assert.assertEquals("jock",account.getName());
    }

}
